#include <stdio.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>

int main()
{
    pid_t pid = fork();
    if (pid == -1)
    {
        perror("fork failed");
        return 1;
    }
    else if (pid == 0)
    {
        // 子进程
        printf("I am the child process. My PID is %d and my parent's PID is %d\n", getpid(), getppid());
        _exit(0);
    }
    else
    {
        int status;
        waitpid(pid, &status, 0);
        printf("子进程执行完毕：%d\n", status);
        // 父进程
        printf("I am the parent process. My PID is %d and my child's PID is %d\n", getpid(), pid);
    }
    return 0;
}